#!/bin/sh

#Copyright (c) 2014 Luigi Tarenga <luigi.tarenga@gmail.com>
#Distributed under the terms of a MIT license.

# parameters: [ lock_name  [ timeout  [ timeout2 ] ] ]

cd ${0%/*}

lname=${1:-default}
timeout=${2:-30}
timeout2=${3:-0}

read lock_servers < conf/lock_servers
echo $((timeout+timeout2))  > temp/${lname}_counter
echo "-invalid-" 0 0 "-invalid-" > temp/${lname}_htvp

hostname=$(hostname)
hostname=${hostname%%.*}

i=0; for h in $lock_servers ; do i=$((i+1)); done
majority=$((i/2+1))
if [ "$majority" -lt "3" ] ; then
   echo "warning. you are using less than 3 lock servers."
   echo "this can easily end in a stale split brain scenario."
   echo
fi

echo $hostname:$majority:$control_master > temp/${lname}_params
